<template>
	<view>
		<view class="detail-list">
			<view class="left">
				<view class="item" :class="{active: active == index}" v-for="(item,index) in showItems" :key="index"
					@click="checkItem(index)">
					{{item.organ}}
				</view>
			</view>
			<view class="right">
				<u-cell-group>
					<u-cell-item v-for="(child, index) in childList" :key='index' :title="child.name"
						@click='toDetail(child)'></u-cell-item>
				</u-cell-group>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		guidance
	} from '@/api/otherService.js'
	export default {
		props: {
			listAll: Array
		},
		data() {
			return {
				showItems: {},
				active: '',
				childList: []
			}
		},
		mounted() {
			console.log(this.listAll)
			this.init()
		},
		methods: {
			init() {
				let map = new Map()
				this.listAll.forEach(item => {
					map.set(item.organ, item);
				})
				this.showItems = [...map].map(item => item[1])
				console.log(this.showItems)
				this.showFirstItem(0)
			},
			// 默认显示第一个
			showFirstItem(index) {
				this.childList = []
				let organ = this.showItems[index].organ
				this.listAll.forEach(item => {
					if (item.organ == organ) {
						this.childList.push(item)
					}
				})
			},
			checkItem(act) {
				this.active = act
				this.showFirstItem(act)
			},
			toDetail(item) {
				uni.navigateTo({
					url: `./Detail?item=` + JSON.stringify(item)
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.detail-list {
		display: flex;
		flex: 1;
		// border-radius: 8px;
		overflow: hidden;
		max-height: calc(100vh);

		.left {
			width: 174upx;
			background-color: #F6F6F6;

			.item {
				line-height: 44upx;
				// border-bottom: 1px solid rgba(0,0,0,0.12);
				padding: 24upx 0 24upx 20upx;
				background-color: #F6F6F6;
				position: relative;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 28upx;
				color: rgba(0, 0, 0, 0.4);
				line-height: 44upx;

				&.active {
					color: $theme-color;
					background-color: #FFF;

					&:before {
						content: '';
						display: block;
						position: absolute;
						width: 6upx;
						height: 64upx;
						left: 0;
						top: 50%;
						transform: translateY(-50%);
						background: $theme-color;
						border-radius: 4upx 0 0 4upx;
					}
				}
			}
		}

		.right {
			flex: 1;
			// padding: 0 32upx 96upx;
			background-color: #FFF;
			overflow: auto;

			.item {
				display: flex;
				justify-content: flex-start;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 28upx;
				color: rgba(0, 0, 0, 0.7);
				line-height: 44upx;
				border-bottom: 1px solid rgba(0, 0, 0, 0.12);
				padding: 24upx 20upx;

				::v-deep.uni-radio-input {
					width: 32upx;
					height: 32upx;
				}

				.money {
					display: flex;
					color: #FF7F7F;
					font-size: 24upx;
					line-height: 40upx;

					.light-min-btn {
						// width: 260upx;
						height: 40upx;
						border-radius: 40upx;
						text-align: center;
						font-size: 24upx;
						background: transparent;
						border: 1px solid $theme-color;
						color: $theme-color;
						padding: 0 16upx;
						margin-left: 32upx;
					}
				}

			}
		}
	}
</style>